#encoding: utf-8

class Activity < ActiveRecord::Base
	belongs_to :user
	has_many :products

	validates :title, presence: {message: "活动标题为空！"}
	validates :desc, presence: {message: "活动描述为空！"}
	validates :start_time, presence: {message: "活动起始时间为空！"}
	validates :end_time, presence: {message: "活动结束为空！"}

	validate :time_order

	def time_order
		if (!self.end_time.nil? && !self.start_time.nil?) && self.end_time <= self.start_time
			errors.add(:end_time, '活动结束时间在开始时间之前！')
		end
	end
end
